//
//  AppDelegate.m
//  A段项目
//
//  Created by dlios on 15/7/9.
//  Copyright (c) 2015年 dlios. All rights reserved.
//

#import "AppDelegate.h"
#import "RecFirstViewController.h"
#import "FindFirstViewController.h"
#import "MyFirstViewController.h"
#import "SerFirstViewController.h"
#import "TalkFirstViewController.h"

@interface AppDelegate ()<UITabBarControllerDelegate>

@end

@implementation AppDelegate

- (void)dealloc
{
    [_window release];
    [super dealloc];
    
}


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    _window.backgroundColor = [UIColor whiteColor];
    [_window makeKeyAndVisible];
    [_window release];
    
    UIImage *image = [UIImage imageNamed:@"main.jpg"];
    UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
    imageView.frame = [[UIScreen mainScreen] bounds];
    [self.window addSubview:imageView];
    [imageView release];
    
    // 进入动画的块
    [UIView animateWithDuration:3 delay:0 options:UIViewAnimationOptionCurveLinear animations:^{
        imageView.alpha = 0;
    } completion:^(BOOL finished) {


    // 推荐
     RecFirstViewController *main = [[RecFirstViewController alloc] init];
    UINavigationController *mainNav = [[UINavigationController alloc] initWithRootViewController:main];
    [main release];
    
    UIImage *image = [UIImage imageNamed:@"2.png"];
    UIImage *aImage = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    main.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"" image:aImage tag:1];
    
    // 发现
    FindFirstViewController *find = [[FindFirstViewController alloc] init];
    UINavigationController *findNav = [[UINavigationController alloc] initWithRootViewController:find];
    [find release];
    
    UIImage *image1 = [UIImage imageNamed:@"3.png"];
    UIImage *bImage = [image1 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    find.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"" image:bImage tag:2];

    
    // 我的
    MyFirstViewController *my = [[MyFirstViewController alloc] init];
    UINavigationController *myNav = [[UINavigationController alloc] initWithRootViewController:my];
    [my release];
    
    UIImage *image2 = [UIImage imageNamed:@"5.png"];
    UIImage *cImage = [image2 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    my.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"" image:cImage tag:3];
    
    // 找车
    SerFirstViewController *search = [[SerFirstViewController alloc] init];
    UINavigationController *searchNav = [[UINavigationController alloc] initWithRootViewController:search];
    [search release];
    
    UIImage *image3 = [UIImage imageNamed:@"7.png"];
    UIImage *dImage = [image3 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    search.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"" image:dImage tag:4];
    
    // 论坛
    TalkFirstViewController *talk = [[TalkFirstViewController alloc] init];
    UINavigationController *talkNav = [[UINavigationController alloc] initWithRootViewController:talk];
    [talk release];
    
    UIImage *image4 = [UIImage imageNamed:@"9.png"];
    UIImage *eImage = [image4 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    talk.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"" image:eImage tag:5];
    
    UITabBarController *tab = [[UITabBarController alloc] init];
    tab.delegate = self;
    tab.viewControllers = @[mainNav, findNav, myNav, searchNav, talkNav];
    
    [mainNav release];
    [findNav release];
    [myNav release];
    [searchNav release];
    [talkNav release];
    
    [_window setRootViewController:tab];
    [tab release];
    
    }];
    
    return YES;
}

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
    UIViewController *main =[tabBarController.viewControllers objectAtIndex:0];
    UIViewController *find =[tabBarController.viewControllers objectAtIndex:1];
     UIViewController *my =[tabBarController.viewControllers objectAtIndex:2];
    UIViewController *search =[tabBarController.viewControllers objectAtIndex:3];
    UIViewController *talk =[tabBarController.viewControllers objectAtIndex:4];
    
    if (tabBarController.selectedIndex == 0) {
        
        find.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"" image:[[UIImage imageNamed:@"3.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] tag:0];
        
       
        my.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"" image:[[UIImage imageNamed:@"5.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] tag:0];
        
        
        search.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"" image:[[UIImage imageNamed:@"7.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] tag:0];
        
        
        talk.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"" image:[[UIImage imageNamed:@"9.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] tag:0];
        
        viewController.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"" image:[UIImage imageNamed:@"2.png"] tag:0];
    }
    if (tabBarController.selectedIndex == 1) {
        
        
        main.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"" image:[[UIImage imageNamed:@"1.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] tag:0];
        
        
        my.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"" image:[[UIImage imageNamed:@"5.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] tag:0];
        
        
        search.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"" image:[[UIImage imageNamed:@"7.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] tag:0];
        
        
        talk.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"" image:[[UIImage imageNamed:@"9.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] tag:0];
        
        viewController.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"" image:[UIImage imageNamed:@"4.png"] tag:0];
    }
    if (tabBarController.selectedIndex == 2) {
        
        
        main.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"" image:[[UIImage imageNamed:@"1.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] tag:0];
        
        
        find.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"" image:[[UIImage imageNamed:@"3.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] tag:0];
        
        
        search.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"" image:[[UIImage imageNamed:@"7.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] tag:0];
        
        
        talk.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"" image:[[UIImage imageNamed:@"9.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] tag:0];
        
        viewController.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"" image:[UIImage imageNamed:@"6.png"] tag:0];
    }
    if (tabBarController.selectedIndex == 3) {
        
        
        main.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"" image:[[UIImage imageNamed:@"1.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] tag:0];
        
        
        find.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"" image:[[UIImage imageNamed:@"3.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] tag:0];
        
        
        my.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"" image:[[UIImage imageNamed:@"5.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] tag:0];
        
        
        talk.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"" image:[[UIImage imageNamed:@"9.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] tag:0];
        
        viewController.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"" image:[UIImage imageNamed:@"8.png"] tag:0];
    }
    if (tabBarController.selectedIndex == 4) {
        
        
        main.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"" image:[[UIImage imageNamed:@"1.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] tag:0];
        
        
        find.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"" image:[[UIImage imageNamed:@"3.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] tag:0];
        
        
        my.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"" image:[[UIImage imageNamed:@"5.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] tag:0];
        
        
        search.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"" image:[[UIImage imageNamed:@"7.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] tag:0];
        
        viewController.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"" image:[UIImage imageNamed:@"10.png"] tag:0];
    }

}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
